package com.edu.d2_stream;

import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Stream;

public class streamTest {
    /**
     * 集合、数组，获取stream流的方式
     */
    public static void main(String[] args) {
        //----------------Collection获取stream流-----------------------
        Collection<String> list = new ArrayList<>();
        Stream<String> stream = list.stream();

        Collection<String> hashSet = new HashSet<>();
        Stream<String> stream1 = hashSet.stream();

        //----------------Map获取stream流--------------------------
        Map<String, String> map = new HashMap<>();
        //获取键流
        Stream<String> keyStream = map.keySet().stream();
        //获取值流
        Stream<String> valuesStream = map.values().stream();
        //获取键值流，先将map集合转换成set集合
        Set<Map.Entry<String, String>> entries = map.entrySet();
        Stream<Map.Entry<String, String>> SetStream = entries.stream();

        //---------------数组获取stream流-------------------
        String[] name={"张三","李四","王五"};
        //第一种：直接使用Arrays自带的stram
        Stream<String> stream2 = Arrays.stream(name);
        stream2.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        //第二种：直接使用stream.of
        Stream<String> stream3 = Stream.of(name);
    }
}
